﻿using System;
using Cesave.Application.Permisos.ServiceAgent.Proxies.PermisosModule;
using System.ServiceModel.Security;
using Cesave.Application.Permisos.Settings;
using Cesave.Infrastructure.CrossCutting.IoC;

namespace Cesave.Application.Permisos.ServiceAgent
{
    public class PermisosModuleServiceWrapper
        : PermisosModuleServiceClient
    {
        public PermisosModuleServiceWrapper()
        {
            IPUSSettings pusSettings = IoCFactory.Resolve<IPUSSettings>();
            if (pusSettings.Agente == null)
                throw new InvalidOperationException("No se han especificado las credenciales del agente.");
            ClientCredentials.UserName.UserName = pusSettings.Agente.Usuario;
            ClientCredentials.UserName.Password = pusSettings.Password;
            ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
        }

        public PermisosModuleServiceWrapper(string username, string password)
        {
            ClientCredentials.UserName.UserName = username;
            ClientCredentials.UserName.Password = password;
            ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
        }

    }
}
